unit productrpt;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Rptbs, RzButton, ComCtrls, StdCtrls, Buttons, ExtCtrls,
  frxClass, frxPreview, frxExportPDF, frxExportXML, frxExportXLS,
  frxExportHTML, frxExportTXT, frxExportRTF, frxExportImage, frxBarcode,
  frxBDEComponents, frxCross, frxDMPExport, frxOLE, frxDCtrl, frxChart,
  frxRich, frxDesgn, frxGZip, frxDBSet, DB, ADODB;

type
  Tproductrptfrm = class(TRptbsfrm)
    procedure FormCreate(Sender: TObject);
    procedure RzBitBtn1Click(Sender: TObject);
    procedure RzBitBtn2Click(Sender: TObject);
    procedure RzBitBtn3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure refreshdb;
    procedure FrmExit;override;
  end;

var
  productrptfrm: Tproductrptfrm;

implementation

{$R *.dfm}

Uses
  Includefile;

procedure Tproductrptfrm.refreshdb;
var
  starttime,endtime:TDateTime;
begin
  starttime:=strdtpicker.DateTime;
  endtime:=enddtpicker.DateTime;
  with dbRpt do begin
    Active:=False;                                       
    SQL.Clear;
    SQL.add('SELECT PRODUCT.PROALIAS,SUM(RECORD.TRAYS) AS TRAYS,SUM(RECORD.NW) AS NW, SUM(RECORD.GW) AS GW,');
    SQL.Add(Format('CDATE(''%s'') AS STATIM, CDate(''%s'') AS ENRTIM',[FormatDateTime('YYYY-MM-DD',starttime),
                        FormatDateTime('YYYY-MM-DD',endtime)]));
    SQL.add('FROM PRODUCT,RECORD');
    SQL.Add('WHERE PRODUCT.PRONAME=RECORD.PRODUCTID');
    SQL.Add(FORMAT('And DATETIME<#%s# And DATETIME>=#%s#',[FormatDateTime('YYYY-MM-DD',endtime+1),
                        FormatDateTime('YYYY-MM-DD',starttime)]));
    if not alwRFID100 then
      SQL.Add(Format('And CLng(Right(RECORD.RFID,%d))>100',[RFIDLen]));
    SQL.add('Group By PROALIAS');
    //showmessage(sql.text);
    ExecSQL;
  end;
  RptDs.UserName:='RECORD';
end;

procedure Tproductrptfrm.FrmExit;
begin
  Hide;
end;

procedure Tproductrptfrm.FormCreate(Sender: TObject);
var
  I:integer;
begin
  inherited;
  for I:=0 to ComponentCount-1 do begin
    if Components[I] is TLabel then begin
      if 0<>TLabel(Components[I]).Tag then
        TLabel(Components[I]).Caption:=
                GetCaption(name,TLabel(Components[I]).Tag);
    end;
    if Components[I] is TRzBitBtn then begin
      if 0<>TRzBitBtn(Components[I]).Tag then
        TRzBitBtn(Components[I]).Caption:=
                GetCaption(name,TRzBitBtn(Components[I]).Tag);
    end;
  end;
  frxReport.LoadFromFile(GetAppPath+'\fr3\product_rpt.fr3');
end;

procedure Tproductrptfrm.RzBitBtn1Click(Sender: TObject);
begin
  inherited;
  refreshDB;
  frxReport.LoadFromFile(GetAppPath+'\fr3\product_rpt.fr3');
  frxReport.ShowReport;
end;

procedure Tproductrptfrm.RzBitBtn2Click(Sender: TObject);
begin
  inherited;
  refreshDB;
  frxReport.DesignReport;
end;

procedure Tproductrptfrm.RzBitBtn3Click(Sender: TObject);
begin
  inherited;
  frxReport.Print;
  refreshDB;
  frxReport.ShowReport;
end;

end.
